package com.stockz.core.util;

import java.util.Collection;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;

@Component
public class SpringUtil{
	
	private static ApplicationContext applicationContext;
	
	public static ApplicationContext getApplicationContext(){
		 initialize();
		return SpringUtil.applicationContext;
	}
	
	public static <T> Collection<? extends T> getBeansOfType(Class<T> type){
		initialize();
		return SpringUtil.applicationContext.getBeansOfType(type).values();
	}
	
	private static void initialize(){
		if(SpringUtil.applicationContext == null)
			SpringUtil.applicationContext = new ClassPathXmlApplicationContext("spring-context.xml");
	}
}
